package org.example;

import java.math.BigDecimal;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Desc:
 * @Author: yanghongjun
 * @Date: 2023/12/12
 **/
public class currency {
    public static ConcurrentHashMap<Integer, BigDecimal> currencyMap;

    /**
     * 单例
     */
    private enum Singleton {

        INSTANCE;
        currency processor;

        Singleton() {
            currencyMap = new ConcurrentHashMap<>();
            currencyMap.put(1, new BigDecimal(0));
            this.processor = new currency();
        }

        currency getProcessor() {

            return processor;
        }
    }

    public static currency getInstance() {
        return currency.Singleton.INSTANCE.getProcessor();
    }


    public void change(int type, BigDecimal decimal) {
        BigDecimal bigDecimal = currencyMap.get(type);
        currencyMap.put(type,bigDecimal.add(decimal));
        System.out.println("变化后" + currencyMap.get(type).toString());
    }

}
